﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using LIM.model;
using LIM.controller;
using Telerik.WinControls.UI;

namespace LIM.forms
{
    public partial class radForm_CRM_BangBaoGiaChiTieu : Telerik.WinControls.UI.RadForm
    {
        public radForm_CRM_BangBaoGiaChiTieu()
        {
            InitializeComponent();
            //radGridView2.DataSource = GetTable();
            this.radTreeView_PhanLoaiChiTieu.TreeViewElement.AllowAlternatingRowColor = true;
        }
        DanhMucBaoGiaController controller = new DanhMucBaoGiaController();
        private void radForm_CRM_DanhSachBaoGia_Load(object sender, EventArgs e)
        {
            LoadDM_LoaiDichVuKiemNghiem();
        }
        private void LoadDM_LoaiDichVuKiemNghiem()
        {
            radTreeView_PhanLoaiChiTieu.Nodes.Clear();
            foreach (tbl_DanhMuc_LoaiDichVuKiemNghiem item in controller.LoadDM_LoaiDichVuKiemNghiem())
            {
                RadTreeNode node1 = new RadTreeNode(item.TenGoi);
                node1.Tag = item.RowID.ToString();
                //node1.Font = new Font("Segoe UI", FontStyle.Bold);
                radTreeView_PhanLoaiChiTieu.Nodes.Add(LoadDM_LoaiMau(item.RowID, node1));
                radTreeView_PhanLoaiChiTieu.ExpandAll();
            }
            //clearcheck();
        }
        private RadTreeNode LoadDM_LoaiMau(int RowIDLoaiDichVuKiemNghiem, RadTreeNode trn)
        {
            foreach (tbl_DanhMuc_LoaiMau itemcon in controller.LoadDM_LoaiMau(RowIDLoaiDichVuKiemNghiem))
            {
                RadTreeNode trcon = new RadTreeNode(itemcon.TenGoi);
                trcon.Tag = itemcon.RowID.ToString();
                trn.Nodes.Add(trcon);
            }
            return trn;
        }

        private void radTreeView_PhanLoaiChiTieu_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
        {
            //int RowID = int.Parse(e.Node.Tag.ToString());
            //if (e.Node.Level == 0)
            //{
            //    radGridView_ChiTieu.DataSource = controller.LoadDM_ChiTieu(RowID, 0);
            //}
            //else
            //{
            //    radGridView_ChiTieu.DataSource = controller.LoadDM_ChiTieu(0, RowID);
            //}
        }

        private void radTreeView_PhanLoaiChiTieu_NodeCheckedChanged(object sender, RadTreeViewEventArgs e)
        {
            int RowID = int.Parse(e.Node.Tag.ToString());
            if (e.Node.Level == 0)
            {
                if (e.Node.Checked == true)
                {
                     radGridView_ChiTieu.DataSource = controller.LoadDM_ChiTieu(RowID, 0);
                }
                else
                {
                    radGridView_ChiTieu.DataSource = null;
                }
                
            }
            else
            {
                List<LIM.controller.ModelCustomize.ClassOneDegitInt> lst = new List<ModelCustomize.ClassOneDegitInt>();
                for (int i = 0; i < radTreeView_PhanLoaiChiTieu.CheckedNodes.Count; i++)
                {
                    if (radTreeView_PhanLoaiChiTieu.CheckedNodes[i].Level == 1)
                    {
                        LIM.controller.ModelCustomize.ClassOneDegitInt one = new ModelCustomize.ClassOneDegitInt();
                        one.Value = int.Parse(radTreeView_PhanLoaiChiTieu.CheckedNodes[i].Tag.ToString());
                        lst.Add(one);
                    }
                }
                if (lst.Count > 0)
                {
                    radGridView_ChiTieu.DataSource = controller.LoadDM_ChiTieu_ByID(lst);
                }
            }
        }
    }
}
